package com.example.springbootmybatis.controller;

import com.example.springbootmybatis.entity.*;
import com.example.springbootmybatis.mapper.BookMapper;
import com.example.springbootmybatis.mapper.MessageMapper;
import com.example.springbootmybatis.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RequestMapping("/message")
@RestController
public class MessageController {

    @Autowired
    MessageMapper messageMapper;


    @RequestMapping("/insertMessage")
    public ResultMap<? extends Object> addMessage(@RequestBody MessageEntity entity) {
        Integer i = messageMapper.addMessage(entity);
        return ToolUtil.getResult(i, "发送");
    }

    @RequestMapping("/getMessageByUid/{uid}")
    public ResultMap<? extends Object> getMessageByUid(@PathVariable("uid") String uid) {
        List<MessageEntity> messages = messageMapper.getMessageByUid(Integer.parseInt(uid));
        return ToolUtil.getResult(messages, "查询");
    }

    @RequestMapping("/getMessageByUid1")
    public ResultMap<? extends Object> getMessageByUid1(@RequestParam("uid") String uid) {
        List<MessageEntity> messages = messageMapper.getMessageByUid(Integer.parseInt(uid));
        return ToolUtil.getResult(messages, "查询");
    }

    @RequestMapping("/setMessageReadUid/{uid}")
    public ResultMap<? extends Object> setMessageReadUid(@PathVariable("uid") String uid) {
        Integer i = messageMapper.setMessageReadUid(Integer.parseInt(uid));
        return ToolUtil.getResult(i, "查询");
    }

//    @RequestMapping("/getBooksByWhere")
//    public ResultMap<? extends Object> getBooksByWhere(@RequestBody BookEntity book) {
//        List<BookEntity> allBooks = bookMapper.getBooksByWhere(book);
//        return ToolUtil.getResult(allBooks, "查询");
//    }


//    @RequestMapping("/deleteUsersByIds")
//    public ResultMap<? extends Object> deleteUsersByIds(@RequestBody List<Integer> ids) {
//        int i = bookMapper.deleteUserByIDs(ids);
//        return ToolUtil.getResult(i, "删除");
//    }

//    @RequestMapping("/updateBookByID")
//    public ResultMap<? extends Object> updateBookByID(@RequestBody BookEntity entity) {
//        int i = bookMapper.updateBookByID(entity);
//        return ToolUtil.getResult(i, "修改");
//    }


//    @RequestMapping("/getBorrowBookInfoByID/{uid}")
//    public ResultMap<? extends Object> getBorrowBookInfoByID(@PathVariable("uid") String uid) {
//        List<BorrowInfo> entity = bookMapper.getBorrowBookInfoByID(Integer.parseInt(uid));
//        return ToolUtil.getResult(entity, "查询");
//    }


}
